package com.example.Arithmetic.Lettcode;

import com.example.Arithmetic.Arithmetic.MinHeap;

/**
 * 日期：2023/10/13
 * 时间：14:07
 * 描述：寻找数据流中第k大的元素
 */
public class E04Lettcode703 {
    MinHeap minHeap;

    public E04Lettcode703(int k, int[] nums) {
        minHeap = new MinHeap(k);
        for (int num : nums) {
            add(num);
        }
    }

    public int add(int val) {
        if (!minHeap.isFull()) {
            minHeap.offer(val);
        } else if (minHeap.peek() < val) {
            minHeap.replace(val);
        }
        return minHeap.peek();
    }
}